//////////////////////////////////////////////////////////////////////////////////
//	ColorControl.cs
//	
//	Written by Cosic Nadin and Franz Thomas Reinisch FH-Joanneum ITM06
//  
//////////////////////////////////////////////////////////////////////////////////


using System;
using System.Collections.Generic;
using System.Text;
using WiimoteLib;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Configuration;
using System.Timers;

namespace WiiFlipChart
{
    class ColorControl
    {

        private Color currentColor;
        private int currentColorNr;
        private String[] arrColor = new String[10];
        


        //offer a public event if the color is changed 
        public event EventHandler ColorChanged;



         static readonly ColorControl instance = new ColorControl();

         public static ColorControl Instance
        {
            get
            {
                return instance;
            }
        }


        /// <summary>
        /// Construcor
        /// Read colors from Config File and save in array
        /// offer a public event if the color is changed 
        /// </summary>
        ColorControl()
        {    
            
                     
            AppSettingsReader config = new AppSettingsReader();

            //Read colors from Config File and save in array
            for (int i=0;i <= 9;i++)
            {
               arrColor[i] = (String)config.GetValue("Color" + Convert.ToString(i + 1), typeof(String));
            }

            currentColor = Color.FromName(arrColor[0]);         
            
            currentColorNr = 1;

        }


      

        /// <summary>
        /// On color change the handler send the event
        /// </summary>
        /// <param name="ea"></param>

       protected void OnColorChanged (EventArgs ea)
       {
          if (ColorChanged != null) 
          {
             ColorChanged (this, ea);
          }
       }


        /// <summary>
        /// Change the current color of the pen
        /// </summary>
        public void changecurrentColor()
        {

                if (currentColorNr == 10)
                {
                    currentColorNr = 0;
                }


                currentColorNr++;
                currentColor = Color.FromName(arrColor[currentColorNr - 1]);

                OnColorChanged(EventArgs.Empty);

        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns> returns the currren color which was selected</returns>
        public Color getcurrentColor()
        {
            return currentColor;
        }


        public String getarrColor(int colorNumber)
        {
            return this.arrColor[colorNumber];
            
        }

  


            
    }
}
